<?php
$objRequest=ClsNaanalRequest::getInstance();
switch($objRequest->getSwitch())
{
    case "config":
        $databaseConfigType=$objRequest->getData("database_config_type");
        $configvars=$objRequest->getData("configvars");
        $arrDatabaseVars=$objRequest->getData("database");
        $loginTable=$objRequest->getData("login_table");
        $homePage=$objRequest->getData("home_page");
        $homeAction=$objRequest->getData("home_action");
        $loginPage=$objRequest->getData("login_page");
        $loginAction=$objRequest->getData("login_action");
        $logoutPage=$objRequest->getData("logout_page");
        $logoutAction=$objRequest->getData("logout_action");
        
        $controlPanel=$objRequest->getData("control_panel");
        
        $enableLog=$objRequest->getData("enable_log")?"true":"false";
        $enableLang=$objRequest->getData("enable_lang")?"true":"false";
        $isDeveloperMode=$objRequest->getData("is_developer_mode")?"true":"false";
        $enableTracking=$objRequest->getData("enable_tracking")?"false":"true";
        $theme=$objRequest->getData("theme")?$objRequest->getData("theme"):"default";
        
        $arrConfigVar=array();
        $arrConfigVar=explode(",",$configvars);
        $staticConfigVar="";
        $staticDatabaseVar="array(";
        if(!empty($arrDatabaseVars))
        {
            $staticDatabaseVar=$staticDatabaseVar."'{$arrDatabaseVars["database"]}'=>array(";
            foreach($arrDatabaseVars as $key=>$var)
            {
                if($key=="database") continue;
                $trimVar=trim($var);
                if(empty($staticConfigVar))
                {
                    $staticConfigVar=$staticConfigVar."'{$key}'=>'{$trimVar}'";
                    $staticDatabaseVar=$staticDatabaseVar."'{$key}'=>'{$trimVar}'";
                }
                else
                {
                    $staticConfigVar=$staticConfigVar.",'{$key}'=>'{$trimVar}'";
                    $staticDatabaseVar=$staticDatabaseVar.",'{$key}'=>'{$trimVar}'";
                }
            }
            $staticDatabaseVar=$staticDatabaseVar.")";
        }
        $staticDatabaseVar=$staticDatabaseVar.")";
        if(!empty($arrConfigVar))
        foreach($arrConfigVar as $ind=>$var)
        {
            $trimVar=trim($var);
            if(empty($trimVar)) continue;
            if(empty($staticConfigVar))
            {
                $staticConfigVar=$staticConfigVar."'{$trimVar}'";
            }
            else
            {
                $staticConfigVar=$staticConfigVar.",'{$trimVar}'";
            }
        }
        $configStaticVars=$staticConfigVar;
        $configControlPanel="";
        if(empty($controlPanel))
        {
            $configControlPanel='array()';
        }
        else
        {
            $configControlPanel="array
(
    '{$controlPanel}'=>array
    (
        'database'=>'{$arrDatabaseVars["database"]}',
        'table'=>array
        (
            'login'=>'{$loginTable}'
        ),
        'page'=>array
        (
            'home'=>array
            (
                'module'=>'{$homePage}',
                'action'=>'{$homeAction}'
            ),
            'login'=>array
            (
                'module'=>'{$loginPage}',
                'action'=>'{$loginAction}'
            ),
            'logout'=>array
            (
                'module'=>'{$logoutPage}',
                'action'=>'{$logoutAction}'
            )
        )
    )
)";
        }
        
        file_put_contents("ClsConfig.php", '<?php
class ClsConfig
{
    static $DATABASE_CONFIG_TYPE="'.$databaseConfigType.'";
    static $DATABASE='.$staticDatabaseVar.';
    static $CONFIG_VAR=array('.$configStaticVars.');
    static $CONTROL_PANEL='.$configControlPanel.';
    static $LOG='.$enableLog.';
    static $LANG='.$enableLang.';
    static $isDeveloperMode='.$isDeveloperMode.';
    static $DISABLE_TRACKING='.$enableTracking.';
    static $theme="'.$theme.'";
}
?>');
        header("Location:index.php");exit;
        break;
        
?>
<?php
    case "default":
?>
    <form action="index.php">
        <input type="hidden" name="page" value="install" />
        <input type="hidden" name="action" value="create" />
        <input type="hidden" name="switch" value="config" />
        <table>
            <tr>
                <td>Database</td><td>:</td><td>
                    <table>
                        <tr>
                            <td>Type</td><td>:</td><td>Variable : <input type="radio" name="database_config_type" value="variable" checked /> Constant : <input type="radio" name="database_config_type" value="constant" /></td>
                        </tr>
                        <tr>
                            <td>Host</td><td>:</td><td><input type="text" name="database[host]" value="host" /></td>
                        </tr>
                        <tr>
                            <td>Server</td><td>:</td><td><input type="text" name="database[server]" value="server" /></td>
                        </tr>
                        <tr>
                            <td>Database</td><td>:</td><td><input type="text" name="database[database]" value="database" /></td>
                        </tr>
                        <tr>
                            <td>User</td><td>:</td><td><input type="text" name="database[user]" value="user" /></td>
                        </tr>
                        <tr>
                            <td>Password</td><td>:</td><td><input type="text" name="database[password]" value="password" /></td>
                        </tr>
                    </table></td>
            </tr>
            <tr>
                <td>Control Panel</td><td>:</td><td>
                    <table>
                        <tr>
                            <td>Name</td><td>:</td><td><input type="text" name="control_panel" value="user" /></td>
                        </tr>
                        <tr>
                            <td>Login Table</td><td>:</td><td><input type="text" name="login_table" value="user" /></td>
                        </tr>
                        <tr>
                            <td>Home Page</td><td>:</td><td>Page: <input type="text" name="home_page" value="home" /> Action: <input type="text" name="home_action" value="create" /></td>
                        </tr>
                        <tr>
                            <td>Login Page</td><td>:</td><td>Page: <input type="text" name="login_page" value="user" /> Action: <input type="text" name="login_action" value="login" /></td>
                        </tr>
                        <tr>
                            <td>Logout Page</td><td>:</td><td>Page: <input type="text" name="logout_page" value="user" /> Action: <input type="text" name="logout_action" value="logout" /></td>
                        </tr>
                        <tr>
                            <td>Name</td><td>:</td><td><input type="text" name="control_panel" value="user" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>Enable Log</td><td>:</td><td><input type="checkbox" name="enable_log" checked /></td><tr>
                <tr><td>Enable Language</td><td>:</td><td><input type="checkbox" name="enable_language" checked /></td><tr>
                <tr><td>Is Developer Mode</td><td>:</td><td><input type="checkbox" name="is_developer_mode" checked /></td><tr>
                <tr><td>Enable Tracking</td><td>:</td><td><input type="checkbox" name="enable_tracking" checked /></td><tr>
                <tr><td>Theme</td><td>:</td><td><input type="text" name="theme" value="default" /></td>
            </tr>
            <tr>
                <td>Other Config Vars</td><td>:</td><td><textarea name="configvars" cols="20"></textarea></td>
            </tr>
            <tr>
                <td style="text-align:center"><center><input type="submit" value="Submit" /></center></td>
            </tr>
        </table>
    </form>
<?php
}
?>